package models

import "time"
import "gorm.io/gorm"
import "go_part/utils"
//import "fmt"

type ApprovalStepModule struct{
	gorm.Model
	Name string
	ApprovalID string
	CompanyID string
	LoginTime time.Time
	IsLogout bool
	DeviceInfo string
 }

func (table *ApprovalStepModule) TableName() string {

	return "approval_module_basic"
}

func GetApprovalStepModuleList() []*ApprovalStepModule { 
	data := make([]*ApprovalStepModule,10)
	utils.DB.Find(&data)
	// for _,v : = range data {
	// 	fmt.Println(v)
	// }
	return data
}

func FindApprovalStepModuleByName(name string) ApprovalStepModule {
	user := ApprovalStepModule{}
	utils.DB.Where("name = ?",name).Find(&user)
	return user
}

func FindApprovalStepModuleByID(id uint) ApprovalStepModule {
	user := ApprovalStepModule{}
	utils.DB.Where("id = ?",id).First(&user)
	return user
}

func FindApprovalStepModuleByCompanyID(id string) []*ApprovalStepModule {
	user := make([]*ApprovalStepModule,100)
	utils.DB.Where("company_id = ?",id).Find(&user)
	return user
}

func CreateApprovalStepModule(user ApprovalStepModule) *gorm.DB {
	
	return utils.DB.Create(&user)
}

func DeleteApprovalStepModule(user ApprovalStepModule) *gorm.DB {
	
	return utils.DB.Delete(&user)
}

func UpdateApprovalStepModule(user ApprovalStepModule) *gorm.DB {
	
	return utils.DB.Model(&user).Updates(ApprovalStepModule{Name: user.Name,DeviceInfo: user.DeviceInfo})
}